/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.List;
import model.Familia;
import org.hibernate.Session;
import org.hibernate.Transaction;
import util.HibernateUtil;

/**
 *
 * @author Fran
 */
public class FamiliaDAO {

    public FamiliaDAO() {
        
        session = HibernateUtil.getSessionFactory().openSession();
        
    }
    
    private Session session;
    
    public void inserir(Familia familia)
    {
        
        Transaction t = session.beginTransaction();
        session.save(familia);
        t.commit();
        
    }
    
    public List<Familia> findAll()
    {
    
        return session.createQuery("from Familia").list();
    
    }
    
    public Familia findById(int id)
    {
    
        return (Familia) session.load(Familia.class, id);
        
    }
    
    public void update(Familia familia){
        
        Transaction t = session.beginTransaction();
        session.merge(familia);
        t.commit();       
        
    }
    
}
